package hot100;

public class rotate {
    public void rotate(int[] nums, int k) {
        k = k % nums.length;

        if(k > 0 && nums.length > 1) {
            //反转0,length
            replace(nums,0,nums.length - 1);
            //反转0，k-1
            replace(nums,0,k - 1);
            //反转k,length
            replace(nums,k,nums.length - 1);
        }
        return;

    }
    public void replace(int[] nums,int l,int r) {
        while(l < r) {
            int tem = nums[l];
            nums[l] = nums[r];
            nums[r] = tem;
            l++;
            r--;
        }
    }
}
